//
//  FirstViewController.m
//  TestGE
//
//  Created by Quoc Dung Chu on 14/07/11.
//  Copyright Paris 6 2011. All rights reserved.
//

#import "FirstViewController.h"
#import "GETuple3d.h"



@implementation FirstViewController

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}

//-----------------------------------------------------------------------------------------------
#pragma mark -
#pragma mark calcul

- (void) _update
{
	_lbT1X.text = [NSString stringWithFormat:@"%d", _t1.X];
	_lbT1Y.text = [NSString stringWithFormat:@"%d", _t1.Y];
	_lbT1Z.text = [NSString stringWithFormat:@"%d", _t1.Z];
	
	_lbT2X.text = [NSString stringWithFormat:@"%d", _t2.X];
	_lbT2Y.text = [NSString stringWithFormat:@"%d", _t2.Y];
	_lbT2Z.text = [NSString stringWithFormat:@"%d", _t2.Z];
}

- (IBAction) create
{
	
	
	int t1X = 0;
	int t1Y = 0;
	int t1Z = 0;
	
	int t2X = 0;
	int t2Y = 0;
	int t2Z = 0;
	
	if ([_tvT1X.text caseInsensitiveCompare:@""] != NSOrderedSame) {
		t1X = [_tvT1X.text intValue];
	}
	
	if ([_tvT1Y.text caseInsensitiveCompare:@""] != NSOrderedSame) {
		t1Y = [_tvT1Y.text intValue];
	}
	
	if ([_tvT1Z.text caseInsensitiveCompare:@""] != NSOrderedSame) {
		t1Z = [_tvT1Z.text intValue];
	}
	
	if ([_tvT2X.text caseInsensitiveCompare:@""] != NSOrderedSame) {
		t2X = [_tvT2X.text intValue];
	}
	
	if ([_tvT2Y.text caseInsensitiveCompare:@""] != NSOrderedSame) {
		t2Y = [_tvT2Y.text intValue];
	}
	
	if ([_tvT2Z.text caseInsensitiveCompare:@""] != NSOrderedSame) {
		t2Z = [_tvT2Z.text intValue];
	}
	
	_t1 = GETuple3d<int>(t1X,t1Y,t1Z);
	_t2 = GETuple3d<int>(t2X,t2Y,t2Z);
	
	GEVector3d<int> v1 = GEVector3d<int>(t1X,t1Y,t1Z);
	GEVector3d<int> v2 = GEVector3d<int>(t2X,t2Y,t2Z);

	NSLog(@"%d",v1.length());
	NSLog(@"test angle vector %f",v1.angleD(v2));
	
	GEPoint3d<int> p1 = GEPoint3d<int>(t1X,t1Y,t1Z);
	GEPoint3d<int> p2 = GEPoint3d<int>(t2X,t2Y,t2Z);

	NSLog(@"distance %d",p1.distance(p2));
	
	GELine3d<int> l1 = GELine3d<int>(t1X,t1Y,t1Z,t2X,t2Y,t2Z);

	
	//NSLog(@"line 3d %d",l1.middle().X);
	
	GELine3d<int> lAbove = GELine3d<int>(1,1,0,3,2,0);
	GEPoint3d<int> pAbove = GEPoint3d<int>(1,1,0);
	NSLog(@"tes above %d",pAbove.isAboveXY(lAbove));
	
	GELine3d<int> l1InterSec = GELine3d<int>(1,1,0,3,2,0);
	GELine3d<int> l2InterSec = GELine3d<int>(0,2,0,1,1,0);

	NSLog(@"test intersect %d",l1InterSec.isIntersectedXY(l2InterSec));
	
	[ self _update];
	
}
//-------------------------------------------------------

- (IBAction) negative
{
	_t1 = (-_t1);
	[ self _update];
	
}

- (IBAction) add
{
	_t1 = _t1+_t2 -_t1 +_t2;
	[ self _update];
	
}


@end
